<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2017/12/12
 * Time: 17:11
 */

namespace app\admin\model;
use think\Model;
class Article extends Model
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
	protected $insert=['status'=>1,'hits'=>0,'review'=>2];

	public  function column(){
		return $this->belongsTo('Column','column_id');
	}
	/**
	 * @param $id
	 * @param string $relation
	 * @return array|false|\PDOStatement|string|Model
	 */
	public static function getonerelation($id,$relation='cate')
	{
			return self::with($relation)->find($id);
	}
	/**
	 * @param $id
	 * @param string $relation
	 * @return false|\PDOStatement|string|\think\Collection
	 */
	public static function getlistrelation($relation,$limit,$columnid)
	{
	    if(!$relation){
            $relation='column';
         }
        $where['column_id']=$columnid;
		return self::with($relation)->where($where)->limit($limit)->order('id desc')->select();
	}
	/**
	 * @param $value
	 * @return string
	 */
	public  function getStatusAttr($value)
	{
		switch ($value) {
			case 1:
				return '正常';
				break;
			case 0:
				return '删除';
				break;
			default;
				break;
		}
	}
    /**
     * @param $value
     * @return string
     */
    public  function getTypeAttr($value)
    {
        switch ($value) {
            case 1:
                return '单篇文章';
                break;
            case 2:
                return '图文信息';
                break;
            default;
                break;
        }
    }
}